﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Bus.Bll;
using Bus.Model;

public partial class config_manageSys : System.Web.UI.Page
{
    private ConfigModel cm = null;//配置实体
    private tb_config confDal = new tb_config();
    protected void Page_Load(object sender, EventArgs e)
    {

       // AjaxPro.Utility.RegisterTypeForAjax(typeof(config_manageSys));
        if (!IsPostBack)
        {
            InitPageData();
        }
    }
    private void InitPageData()
    {
        List<ConfigModel> mlist = confDal.GetModelList(string.Empty);
        foreach (ConfigModel item in mlist)
        {
            if (item.configname == "studentConfig")
                stud.Text = item.val.ToString().Trim();
            if (item.configname == "laorenConfig")
                TextBox1.Text = item.val.ToString().Trim();
            if (item.configname == "chengnianrenConfig")
                TextBox2.Text = item.val.ToString().Trim();
            
        }
        
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        if (ValidateText(stud))
        {
            Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('值不能为空');</script>");
            return;
        }
        cm = new ConfigModel();
        cm.configname = "studentConfig";
        cm.val = decimal.Parse(stud.Text.ToString().Trim());
        cm.m1 = "学生配置选项";
        if (!confDal.Exists(confDal.studSql))
        {           
            confDal.Add(cm);
        }
        else
        {
            confDal.Update(cm);
        }

    }
    protected void buttom_Click(object sender, EventArgs e)
    {
        if (ValidateText(TextBox1))
        {
            Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('值不能为空');</script>");
            return;
        }
        cm = new ConfigModel();
        cm.configname = "laorenConfig";
        cm.val = decimal.Parse(TextBox1.Text.Trim());
        cm.m1 = "老人配置选项";

        if (!confDal.Exists(confDal.lrSql))
        {
            confDal.Add(cm);
        }
        else
        {
            confDal.Update(cm);
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (ValidateText(TextBox2))
        {
            Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('值不能为空');</script>");
            return;
        }
        cm = new ConfigModel();
        cm.configname = "chengnianrenConfig";
        cm.val = decimal.Parse(TextBox2.Text.Trim());
        cm.m1 = "成年人配置选项";
        if (!confDal.Exists(confDal.crSql))
        {
            confDal.Add(cm);
        }
        else
        {
            confDal.Update(cm);
        }
    }
    private Boolean ValidateText(TextBox tb)
    {
        if (tb.Text == string.Empty)
        {
            return true ;
        }
        else
        {
            return false;
        }
    }
}
